package com.zjh.accountServer.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zjh.accountServer.mapper.AdminMapper;
import com.zjh.accountServer.mapper.UserMapper;
import com.zjh.entity.Admin;
import com.zjh.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: AccountController
 * Description:
 * @Author zjh
 * @Create 2023/10/30 11:03
 */
@RestController
@RequestMapping("/account")
public class AccountController {
	
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private AdminMapper adminMapper;
	
	
	@GetMapping("login/{username}/{password}/{type}")
	public Object login(@PathVariable String username, @PathVariable String password,
	                    @PathVariable String type){
		if("user".equals(type)){
//			return userMapper.login(username,password);
			LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>();
			queryWrapper.eq(User::getUsername,username).eq(User::getPassword,password);
			return userMapper.selectOne(queryWrapper);
		}
//		return adminMapper.login(username,password);
		LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(Admin::getUsername,username).eq(Admin::getPassword,password);
		return adminMapper.selectOne(wrapper);
	}
}
